package sicau.carManager.config;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import sicau.carManager.Util.TokenUtil.TokenUtil;
import sicau.carManager.entity.Admin;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.net.URLEncoder;

/**
 * @Author ITcz
 * @Data 2021-02-10 - 16:18
 * 对超级管理员的权限检验
 */
@Component
public class SuperAdminIntercepter extends HandlerInterceptorAdapter {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
            throws Exception {
        //获取请求头里的token
        String token = request.getHeader("token");
        Admin admin = TokenUtil.getAdminByToken(token);
        //获取权限，0是普通管理员，1是超级管理员
        int i = admin.getAuthority();
        if (i == 0) {
            request.setAttribute("msg", "你的权限不够");
            response.sendRedirect("http://114.55.33.243:8081");
            return false;
        }
        return true;
    }

}
